# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
===========================
@Time : 2022/10/10 0010 23:49
@Author : 测试开发工程师
@File : goods_grounding_page.py
@Software: PyCharm
============================
"""
from selenium.webdriver.common.by import By
from last_testweb.Litemall_Project.page_objects.base_page import BasePage


class GoodsGroundingPage(BasePage):
    _INPUT_GOODS_NUM = (By.XPATH, "//label[@for='goodsSn']/..//*[@class='el-input__inner']")
    _INPUT_GOODS_NAME = (By.XPATH, "//label[@for='name']/..//*[@class='el-input__inner']")
    _INPUT_GOODS_PRICE = (By.XPATH, "//label[@for='counterPrice']/..//*[@class='el-input__inner']")
    _RADIO_HOT = (By.XPATH, "//span[contains(text(),'热卖')]")
    _BNT_GOUNDING_BUTTON = (By.XPATH, "//div[@class='op-container']//span[contains(text(),'上架')]")

    def goods_grounding(self, goodsSn, name, price):
        from last_testweb.Litemall_Project.page_objects.goods_list_page import GoodsListPage
        # 输入 [商品编号]
        self.do_send_keys(*self._INPUT_GOODS_NUM, goodsSn)
        # 输入 [商品名称]
        self.do_send_keys(*self._INPUT_GOODS_NAME, name)
        # 输入 [商品售价]
        self.do_send_keys(*self._INPUT_GOODS_PRICE, price)
        # 选择 [热卖]
        self.do_click(*self._RADIO_HOT)
        # js 滑动到当前页面最底部
        self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
        # 点击 [上架] 按钮
        self.do_click(*self._BNT_GOUNDING_BUTTON)

        return GoodsListPage(self.driver)
